import { createApp } from 'vue'
import 'element-plus/dist/index.css'
import './style/element_visiable.scss'
import ElementPlus from 'element-plus'
import ReadonlyFormItem from 'element-plus-readonly-form-item'
import zhCn from 'element-plus/es/locale/lang/zh-cn'

// 引入封装的router
import router from '@/router/index'
import '@/permission'
// 引入vue-admin前端初始化相关内容
import run from '@/core/vue-admin.js'
import { store } from '@/pinia'
import App from './App.vue'
import preventRepeatClick from '@/utils/directive.js'
// 消除element-plus组件的一些不兼容的问题
import 'default-passive-events' // 去除表单form校验警告信息
import funnyGames from 'funny-games'

/**
 * @description 导入加载进度条，防止首屏加载时间过长，用户等待
 **/
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
Nprogress.configure({ showSpinner: false, ease: 'ease', speed: 500 })
Nprogress.start()
/**
 * 无需在这块结束，会在路由中间件中结束此块内容
 * */

// 自定义封装组件
import components from '@/components/index'
// 打印模块
import print from 'vue3-print-nb'

const app = createApp(App)
app.config.productionTip = false

// 注册金钱单位显示指令
app.directive('money', {
  mounted(el, { value }) {
    if (value === null || value === undefined || value === '') {
      el.innerText = ''
    } else {
      el.innerText = String(value).replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
    }
  },
  updated(el, { value }) {
    if (value === null || value === undefined || value === '') {
      el.innerText = ''
    } else {
      el.innerText = String(value).replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
    }
  }
})

app
  .use(run)
  .use(store)
  .use(components)
  .use(print)
  .use(router)
  .use(preventRepeatClick)
  .use(funnyGames)
  .use(ElementPlus, { locale: zhCn })
  .use(ReadonlyFormItem, { emptyText: '--' })
  .mount('#app')

export default app
